//
//  WhzPDDSearchGoodsCell.m
//  WhzPinDuoDuo
//
//  Created by whz on 16/11/17.
//  Copyright © 2016年 whz. All rights reserved.
//

#import "WhzPDDSearchGoodsCell.h"
#import <UIImageView+WebCache.h>
#import <Masonry.h>

@interface WhzPDDSearchGoodsCell ()

/**
 商品配图
 */
@property(nonatomic, strong)UIImageView *imageViewGoods;
/**
 商品名称
 */
@property(nonatomic, strong)UILabel *labelGoods;

@end

@implementation WhzPDDSearchGoodsCell

- (instancetype)initWithFrame:(CGRect)frame {

    if (self = [super initWithFrame:frame]) {
        
        [self setupUI];
    }
    return self;
}

#pragma mark - 初始化UI
- (void)setupUI {
    
    CGFloat margin = 8;

    // MARK: - 商品配图
    self.imageViewGoods = [[UIImageView alloc] init];
    [self.contentView addSubview:self.imageViewGoods];
    [self.imageViewGoods mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(margin);
        make.left.equalTo(self.mas_left).offset(margin);
        make.right.equalTo(self.mas_right).offset(-margin);
    }];
    
    // MARK: -  商品名字
    self.labelGoods = [[UILabel alloc] init];
    self.labelGoods.text = @"名称";
    self.labelGoods.font = [UIFont systemFontOfSize:13];
    self.labelGoods.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:self.labelGoods];
    [self.labelGoods mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imageViewGoods.mas_bottom).offset(margin);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-margin);
        make.centerX.equalTo(self.mas_centerX);
    }];
}

/**
 重写set方法 赋值

 @param rootModel 数组模型
 */
- (void)setRootModel:(NSArray<WhzPDDRootModel *> *)rootModel {

    _rootModel = rootModel;
    
    [self.imageViewGoods sd_setImageWithURL:[NSURL URLWithString:rootModel[self.indexPathForSection].children[self.indexPathForRow].image_url]];
    
    self.labelGoods.text = rootModel[self.indexPathForSection].children[self.indexPathForRow].opt_name;
}

@end
